#ifndef LUCNX_LIST_H
#define LUCNX_LIST_H

#include <Lucnx/types.h>

#define offset(type, member) (u32)&(((type*)0)->member)
#define member2entry(type, member, ptr) (type*) ((u32)ptr - offset(type, member))

typedef struct list_node
{
    struct list_node *next;
    struct list_node *prev;
}_packed list_node;

typedef struct list
{
    list_node head;
    list_node tail;
}_packed list;

void list_init(list *p_list);
void list_inside(list_node *before, list_node *node);
void list_remove(list_node *node);
list_node *list_pop(list *p_list);
void list_push(list *p_list, list *node);
void list_add_end(list *p_list, list_node *node);
bool list_find(list *p_list, list_node *node);
bool list_null(list *p_list);

#endif